# Here is a short solution with a dict comprehension.
# The lesson gives an example of how to do this with an explicit loop.
# scores = {leaf_size: get_mae(leaf_size, train_X, val_X, train_y, val_y) for leaf_size in candidate_max_leaf_nodes}
# best_tree_size = min(scores, key=scores.get)


# another way with loops
# candidate_max_leaf_nodes = [5, 25, 50, 100, 250, 500]
# # Write loop to find the ideal tree size from candidate_max_leaf_nodes
# start_mae = get_mae(5,train_X, val_X, train_y, val_y)
# start_leaf_node = 5
# for lead_node in candidate_max_leaf_nodes:
#     mae_now = get_mae(lead_node,train_X, val_X, train_y, val_y)
#     if  mae_now <= start_mae:
#         start_mae = mae_now
#         start_leaf_node = lead_node
# # Store the best value of max_leaf_nodes (it will be either 5, 25, 50, 100, 250 or 500)
# best_tree_size = start_leaf_node
